using System;
using BitMango;
using UnityEngine;

public static class DWATTLight
{
    static DWATTLight()
    {
        DWATTLight.formatVersion = "2";
        DWATTLight.OS = WWW.EscapeURL(SystemInfo.operatingSystem);
        DWATTLight.deviceModel = WWW.EscapeURL(SystemInfo.deviceModel);
        DWATTLight.storeType = PlatformContext.StoreType.GoogleStore.ToString();
    }

    public static string Prefix
    {
        set
        {
            DWATTLight.prefix = value;
        }
    }

    public static void logEvent(string eventName, params object[] ps)
    {
        //if (Platform.IsEU())
        //{
        //    UnityEngine.Debug.Log("DWATTLight.logEvent - Can't send log to EU users");
        //    return;
        //}
        //string text = "&e=" + WWW.EscapeURL(eventName);
        //string text2 = "DWATTLight.logEvent:" + eventName;
        //string url = (!(eventName == "impression")) ? DWATTLight.analyticsLogURL : DWATTLight.analytics2LogURL;
        //for (int i = 0; i < ps.Length; i++)
        //{
        //    text += string.Format("&v{0}={1}", i + 1, (ps[i] != null) ? WWW.EscapeURL(ps[i].ToString()) : string.Empty);
        //    text2 += string.Format(" v{0}:{1}", i + 1, (ps[i] != null) ? ps[i].ToString() : string.Empty);
        //}
        //FirebaseAnalyticsHelper.logEvent(eventName, ps);
        //UnityEngine.Debug.Log(text2);
        //DWATTLight.SendLog(url, text);
    }

    private static void SendLog(string URL, string param)
    {
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            return;
        }
        string text = string.Concat(new string[]
        {
            "log.xlg?a=",
            DWATTLight.appID,
            "&u=",
            Profile.UUID,
            "&aid=",
            Profile.ADID,
            "&v=",
            DWATTLight.version,
            DWATTLight.prefix,
            "&f=",
            DWATTLight.formatVersion,
            "&s=",
            DWATTLight.storeType,
            "&o=",
            DWATTLight.OS,
            "&d=",
            DWATTLight.deviceModel,
            "&it=",
            Profile.InstallTimeStr,
            "&iv=",
            Profile.InstallVersion,
            DWATTLight.prefix
        });
        UnityEngine.Debug.Log("DWATTLight.SendLog logParam : " + text + " Param : " + param);
        WWW www = new WWW(string.Concat(new string[]
        {
            URL,
            text,
            param,
            "&ts=",
            WWW.EscapeURL(DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + " GMT")
        }));
    }

    private static string EncodeWithKey(string text, string key)
    {
        byte[] array = new byte[text.Length];
        for (int i = 0; i < text.Length; i++)
        {
            array[i] = (byte)(text[i] ^ key[i % key.Length]);
        }
        return Convert.ToBase64String(array, 0, array.Length);
    }

    private static string appID;

    private static string version;

    private static string OS;

    private static string deviceModel;

    private static string formatVersion;

    private static string storeType;

    private static string prefix = string.Empty;

    //private static string analyticsLogURL = "https://a.bitmango.com/";

    //private static string analytics2LogURL = "https://a2.bitmango.com/";
}
